package org.za.communication.core.codec;

import java.util.ArrayList;
import java.util.List;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.za.communication.core.codec.decoder.DataSegmentationDecoder;
import org.za.communication.core.codec.encoder.DataCombineEncoder;

public class CodecFactory implements ProtocolCodecFactory {
	private DataSegmentationDecoder decoder;
	private DataCombineEncoder encoder;

	public CodecFactory() {

		byte[] head = new byte[2];
		head[0] = (byte) 0xff;
		head[1] = (byte) 0xff;

		List<Integer> l = new ArrayList<Integer>();
		l.add(0x01);
		l.add(0x02);
		l.add(0x03);
		l.add(0x05);
		l.add(0x06);

		List<Integer> l2 = new ArrayList<Integer>();
		l2.add(0x04);
		l2.add(0x52);
		l2.add(0x53);
		l2.add(0x54);

		encoder = new DataCombineEncoder();
		encoder.setHead(head);
		encoder.setEncryptIdList(l);

		decoder = new DataSegmentationDecoder();
		decoder.setHead(head);
		decoder.setDecryptIdList(l2);

	}

	@Override
	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
		return decoder;
	}

	@Override
	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
		return encoder;
	}

}
